<?php
/**
 * Created by PhpStorm.
 * User: 悟能科技
 * Date: 2018/8/30
 * Time: 16:13
 */

namespace app\mobile\controller;


use app\common\model\CardQrcode;
use app\common\model\CardShareUser;
use think\Controller;
use think\Request;

class CardOpen extends Controller
{

    public function index(Request $request){
//        try {
        $param = $request->param();
        if (isset($param['type'])) {
            if ($param['type'] == 'OLD') {
                $map['type'] = 0;
            } else {
                $map['type'] = 1;
            }
            $map['id'] = $param['qrcode'];
            $CardQrcode = new CardQrcode();
            $qrcode = $CardQrcode->where($map)->field('url')->find();
            $this->redirect($qrcode['url']);
        }else{
            echo "系统繁忙，请稍后再试！！！";
        }
//        }catch (\Exception $e){
//            echo "系统繁忙，请稍后再试！！！".$e->getMessage();
//        }
    }

    //
    public function share(Request $request){
//        try {
        $param = $request->param();
        if (isset($param['share'])) {
            $map['id'] = $param['share'];
            $CardShareUser = new CardShareUser();
            $qrcode = $CardShareUser->where($map)->field('biz_url')->find();
            $this->redirect($qrcode['biz_url']);
        }else{
            echo "系统繁忙，请稍后再试！！！";
        }
//        }catch (\Exception $e){
//            echo "系统繁忙，请稍后再试！！！";
//        }
    }
}